<?php
/**
 * Copyright (c) 2006, PORTALIER Julien
 *
 * Licensed under The LGPL License
 * Redistributions of files must retain the above copyright notice.
 *
 * @package      FeatherCMS
 * @subpackage   Invitation
 * @copyright    Copyright (c) 2006, Julien PORTALIER
 * @link         http://julien.portalier.com
 * @license      http://www.opensource.org/licenses/lgpl-license.php The LGPL License
 */

class InviteController extends Controller
{
	public $uses = 'Invitation';
	
	function index()
	{
		// restricted access
		if ($this->acl->identified)
		{
			$invitations = $this->Invitation->Member->field('invitations', $this->acl->id, -1);
			if ((int)$invitations !== 0 and $invitations < 2)
				$this->acl->permissionDenied();
		}
		else
			$this->acl->permissionDenied();
		
		if (!empty($this->data))
		{
			if ($this->Invite->save())
			{
				// sends invitation
				$this->load->component('email');
				$this->email->addRecipient($this->data['Invitation']['email']);
				$this->email->send(_("Invitation from %s", $this->acl->id));
				
				$this->session->setFlash(_('Invitation sent to %s', $this->data['Invitation']['email']));
			}
			else
				$this->session->setFlash(_('Oops, an error occured.'));
		}
		
		$this->pageTitle = _("Invite a friend.");
	}
}
?>